//
//  SecondTableViewCell.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/22.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "SecondTableViewCell.h"
#import "SecondCellButton.h"

#define Margin 8

#define SecondCellHeight 88

@interface SecondTableViewCell ()<SecondCellButtonDelegate>

@property (nonatomic,strong)SecondCellButton *leftButton;

@property (nonatomic,strong)SecondCellButton *rightButton;

@end

@implementation SecondTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self loadSecondCell];
        
    }
    return self;
}

- (void)loadSecondCell {
    UILabel *firstLabel = [[UILabel alloc] init];
    firstLabel.text = @"会员支付方式";
    firstLabel.textAlignment = NSTextAlignmentLeft;
    firstLabel.font = [UIFont systemFontOfSize:15];
    firstLabel.font = [UIFont fontWithName:@ "Arial Rounded MT Bold"  size:(15.0)];
    [self.contentView addSubview:firstLabel];
    
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin *2);
        make.top.equalTo(self.contentView.mas_top);
        make.width.mas_equalTo(WIDTH * 0.3);
        make.height.mas_equalTo(SecondCellHeight/2);
    }];
    
    UIView *leftView = [[UIView alloc] init];
//    leftView.backgroundColor = [UIColor yellowColor];
    leftView.userInteractionEnabled = NO;
    [self.contentView addSubview:leftView];
    
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstLabel.mas_bottom);
        make.left.equalTo(self.contentView.mas_left);
        make.width.mas_equalTo(WIDTH / 2);
        make.height.mas_equalTo(SecondCellHeight / 2);
    }];
    
    SecondCellButton *leftButton = [[SecondCellButton alloc] init];
    leftButton.tag = 2;
    leftButton.delegate = self;
    [leftButton addTarget:self action:@selector(didClickChooseTypeButton:) forControlEvents:UIControlEventTouchUpInside];
    leftButton.firstlabel.text = @"赠送代金券";
//    self.zengSong = ffView1;
    [leftView addSubview:leftButton];
    [self.contentView addSubview:leftButton];
    self.leftButton = leftButton;
    
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(leftView.mas_centerY);
        make.centerX.equalTo(leftView.mas_centerX);
        make.width.mas_equalTo(WIDTH/3);
        make.height.mas_equalTo(20);
    }];
    
    UIView *rightView = [[UIView alloc] init];
//    rightView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:rightView];
    
    SecondCellButton *rightButton = [[SecondCellButton alloc] init];
    rightButton.tag = 1;
    rightButton.delegate = self;
    [rightButton addTarget:self action:@selector(didClickChooseTypeButton:) forControlEvents:UIControlEventTouchUpInside];
    rightButton.firstview.backgroundColor = [UIColor whiteColor];
    rightButton.firstlabel.text = @"现金";
    [rightView addSubview:rightButton];
    [self.contentView addSubview:rightButton];
    self.rightButton = rightButton;
    
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(SecondCellHeight/2);
        make.left.equalTo(leftView.mas_right);
        make.width.mas_equalTo(WIDTH/2);
        make.height.mas_equalTo(SecondCellHeight/2);
    }];
    
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(rightView.mas_centerY);
        make.centerX.equalTo(rightView.mas_centerX);
        make.width.mas_equalTo(WIDTH/5);
        make.height.mas_equalTo(20);
    }];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)didClickChooseTypeButton:(SecondCellButton *)ChooseButtonType {
    
    if (ChooseButtonType.tag == 1) {
        self.leftButton.firstview.backgroundColor = [UIColor whiteColor];
        self.rightButton.firstview.backgroundColor = DEFAULT_COLOR;
    } else {
        self.leftButton.firstview.backgroundColor = DEFAULT_COLOR;
        self.rightButton.firstview.backgroundColor = [UIColor whiteColor];
    }
    
    
    if ([self.delegate respondsToSelector:@selector(SecondTableViewCellButtonDelegate:)]) {
        [self.delegate SecondTableViewCellButtonDelegate:ChooseButtonType];
    }
    
}

- (void)SecondCellButtonClick:(UIButton *)button {
    NSLog(@"%s",__func__);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
